package com.spring.springboot.sys.base;

import com.spring.springboot.sys.core.enums.ResponseCodeEnum;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author 宋义州
 * @date 2022-07-26  00:05
 * @description 自定义异常
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class ServiceException extends RuntimeException {

    private Integer code;

    private String errorMessage;

    /**
     * @param code         状态码
     * @param errorMessage 错误信息
     */
    public ServiceException(Integer code, String errorMessage) {
        super(errorMessage);
        this.code = code;
        this.errorMessage = errorMessage;
    }

    /**
     * 自定义异常
     *
     * @param responseCodeEnum 自定义状态码
     */
    public ServiceException(ResponseCodeEnum responseCodeEnum) {
        super(responseCodeEnum.getMessage());
        this.code = responseCodeEnum.getCode();
        this.errorMessage = responseCodeEnum.getMessage();
    }

}
